package org.wukongcrm.domain.model;

import lombok.Data;

/**
 * 响应对象
 *
 * @author ZhongWang
 * @since 2024 12 17:16:25
 */
@Data
public class R<T> {

    /**
     * 响应状态码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

    public static <T> R<T> success() {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMsg("success");
        return r;
    }

    public static <T> R<T> success(Integer code) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg("success");
        return r;
    }

    public static <T> R<T> success(Integer code, String msg, T data) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> R<T> success(String msg, T data) {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMsg("success");
        r.setData(data);
        return r;
    }

    public static <T> R<T> error(Integer code) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg("fail");
        return r;
    }

    public static <T> R<T> error(Integer code, String msg, T data) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> R<T> error(String msg, T data) {
        R<T> r = new R<>();
        r.setCode(500);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static <T> R<T> error(T data) {
        R<T> r = new R<>();
        r.setCode(500);
        r.setMsg("fail");
        r.setData(data);
        return r;
    }

    public static <T> R<T> error() {
        R<T> r = new R<>();
        r.setCode(500);
        return r;
    }

}
